import { createRouter, createWebHashHistory } from 'vue-router'
import DefaultLayout from '@/layouts/DefaultLayout.vue'
import HomeView from '../views/HomeView.vue'
import LoginView from '@/views/auth/LoginView.vue'
import SettingsLayout from '@/layouts/SettingsLayout.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: DefaultLayout,
      children: [
        {
          path: '',
          name: 'home',
          component: HomeView,
        },
        {
          path: '/403',
          name: 'ForbiddenPage',
          component: () => import('@/views/error/403.vue'),
          meta: {
            title: '无权限访问',
          },
        },
        {
          path: 'settings',
          component: SettingsLayout,
          meta: { requiresAuth: true },
          children: [
            {
              path: 'system-users',
              name: 'system-users',
              component: () => import('@/views/system/SystemUser.vue'),
              meta: { title: '系统用户', permissions: ['system:users:list'] },
            },
            {
              path: 'permissionFeature',
              name: 'permissionFeature',
              component: () => import('@/views/system/PermissionFeature.vue'),
              meta: { title: '功能权限', permissions: ['permission:feature:list'] },
            },
            {
              path: 'systemRole',
              name: 'systemRole',
              component: () => import('@/views/system/SystemRole.vue'),
              meta: { title: '角色管理', permissions: ['system:role:list'] },
            },
          ],
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: LoginView,
    },
  ],
})

export default router
